/*
 * DialogParam.java
 *
 * Created on March 10, 2008, 4:40 PM
 */
package botoseis.iview.dialogs;

import java.text.DecimalFormat;
import botoseis.iview.utils.NumericDoc;

/**
 * BotoSeis project
 * 
 * Imaging and interpretation group, Geophics dep. UFPA - Brazil
 *
 * @author  Iran Gadelha
 *          Williams Lima, williams_al@gmx.com
 */
public class DialogParametersImage extends javax.swing.JDialog {

    /** Creates new form DialogParam */
    public DialogParametersImage(java.awt.Frame parent, boolean modal, gfx.SVColorScale csActor, gfx.SVWiggle wgActor, javax.swing.JPanel pPanel) {
        super(parent, modal);
        initComponents();

        m_csActor = csActor;
        m_wgActor = wgActor;
        m_plotPanel = pPanel;

        image_perc.setDocument(new NumericDoc());
//        image_bperc.setDocument(new utils.NumericDoc());
//        image_wperc.setDocument(new utils.NumericDoc());
//        image_bclip.setDocument(new utils.NumericDoc());
//        image_wclip.setDocument(new utils.NumericDoc());
        image_balance.setDocument(new NumericDoc());

        wigb_perc.setDocument(new NumericDoc());
//        wigb_clip.setDocument(new utils.NumericDoc());
//        wigb_xcut.setDocument(new utils.NumericDoc());
//        wigb_wt.setDocument(new utils.NumericDoc());
//        wigb_va.setDocument(new utils.NumericDoc());
//        
//        gain_panel.setDocument(new utils.NumericDoc());
//        gain_agc.setDocument(new utils.NumericDoc());
//        gain_gagc.setDocument(new utils.NumericDoc());
//        gain_wagc.setDocument(new utils.NumericDoc());
//        gain_scale.setDocument(new utils.NumericDoc());
//        gain_norm.setDocument(new utils.NumericDoc());
//        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnOk = new javax.swing.JButton();
        btnCancel = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        image_perc = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        image_balance = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        wigb_perc = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        btnaplicar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Parameters Image"); // NOI18N

        btnOk.setMnemonic('O');
        btnOk.setText("OK"); // NOI18N
        btnOk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOkActionPerformed(evt);
            }
        });

        btnCancel.setMnemonic('C');
        btnCancel.setText("Cancel"); // NOI18N
        btnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Image"));

        image_perc.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        jLabel1.setText("perc"); // NOI18N
        jLabel1.setOpaque(true);

        jLabel6.setText("balance"); // NOI18N

        image_balance.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(image_perc, javax.swing.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(image_balance, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(image_perc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(image_balance, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Wigb"));

        wigb_perc.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        jLabel7.setText("perc"); // NOI18N
        jLabel7.setOpaque(true);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel7)
                .addGap(35, 35, 35)
                .addComponent(wigb_perc, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE)
                .addGap(21, 21, 21))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(wigb_perc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        btnaplicar.setMnemonic('O');
        btnaplicar.setText("Apply"); // NOI18N
        btnaplicar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnaplicarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnaplicar, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnOk, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(171, 171, 171))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnaplicar, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnOk, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(30, Short.MAX_VALUE))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-302)/2, (screenSize.height-282)/2, 302, 282);
    }// </editor-fold>//GEN-END:initComponents
    private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
        verifyimage = 0;
        if (apply) {
            m_wgActor.setPercParameters(wigbperc_old);//, wigbclip);
            m_csActor.setImagePerc(imageperc_old);
            //  m_csActor.setPercParameters(imageperc_old, imagebperc, imagewperc);
            m_csActor.setbalance(imagebalance_old);
            m_plotPanel.repaint();
        }
        setVisible(false);

}//GEN-LAST:event_btnCancelActionPerformed

    public int getParameterVerifyimage() {
        return verifyimage;
    }

    private void btnOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOkActionPerformed

        verifyimage = 1;
        setVisible(false);
    }//GEN-LAST:event_btnOkActionPerformed

private void btnaplicarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnaplicarActionPerformed
    apply = true;
    wigbperc = Float.parseFloat(wigb_perc.getText());
    imageperc = Float.parseFloat(image_perc.getText());
    imagebalance = (int) Float.parseFloat(image_balance.getText());


    if (m_wgActor != null) {

        m_wgActor.setPercParameters(wigbperc);//, wigbclip);
    }
    //codigo para imagem
    if (m_csActor != null) {

        if ((imageperc < 0) || (imageperc > 100)) {
            imageperc = 100.0f;
        }

        if ((imagebalance != 1) && (imagebalance != 0)) {
            imagebalance = 0;
        }
        m_csActor.setImagePerc(imageperc);
        m_csActor.setbalance(imagebalance);

    }

    m_plotPanel.repaint();
}//GEN-LAST:event_btnaplicarActionPerformed
    //**************parameter para image *******************

    public void setimage_perc(float perc) {
        imageperc_old = perc;
        DecimalFormat df = new DecimalFormat("0.###");
        String imagepercST_old = df.format(imageperc_old);
        image_perc.setText(imagepercST_old);
    }

    public float getimage_perc() {
        imageperc = Float.parseFloat(image_perc.getText());
        return imageperc;
    }

    public void setimage_balance(int balance) {
        imagebalance_old = balance;
        DecimalFormat df = new DecimalFormat("0.###");
        String imagebalanceST_old = df.format(imagebalance_old);
        image_balance.setText(imagebalanceST_old);
    }

    public float getimage_balance() {
        imagebalance = (int) Float.parseFloat(image_balance.getText());
        return imagebalance;
    }
    //************** fim dos parameter para image *******************

    //************** parameter para gain *******************
    //************** parameter para wigb *******************
    public void setwigb_perc(float wperc) {
        wigbperc_old = wperc;
        DecimalFormat df = new DecimalFormat("0.###");
        String wigbpercST_old = df.format(wigbperc_old);
        wigb_perc.setText(wigbpercST_old);
    }

    public float getwigb_perc() {
        wigbperc = Float.parseFloat(wigb_perc.getText());
        return wigbperc;
    }
//                               
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btnOk;
    private javax.swing.JButton btnaplicar;
    private javax.swing.JTextField image_balance;
    private javax.swing.JTextField image_perc;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTextField wigb_perc;
    // End of variables declaration//GEN-END:variables
    usrdata.SUSection m_secZO;
//    float radius;
//    float timeWindow;
//    float surfaceVelocity;
    int verifyimage;
    float imageperc;
    float imageperc_old;
    float imagebperc;
    float imagewperc;
    float imageclip;
    float imagebclip;
    float imagewclip;
    int imagebalance;
    int imagebalance_old;
    float gainpanel;
    float gainagc;
    float gaingagc;
    float gainwagc;
    float gainscale;
    float gainnorm;
    float wigbperc;
    float wigbperc_old;
    float wigbclip;
    float wigbxcur;
    float wigbwt;
    float wigbva;
    boolean apply = false;
    gfx.SVColorScale m_csActor = null;
    gfx.SVWiggle m_wgActor;
    javax.swing.JPanel m_plotPanel;
}
